import {
	defineStore
} from 'pinia'
import {
	getHomeBanner,
	getHomeActivity,
	getTableData,
	getActivityDetail
} from '../api/homeData'

export const useHomeStore = defineStore('home', {
	state: () => ({
		banner: [],
		activity: [],
		table: [],
		activityDetail:{}
	}),
	actions: {
		// 轮播图
		async getBannerData() {
			try {
				const res = await getHomeBanner()
				this.banner = res.data
			} catch (error) {
				console.log(error)
			}
		},
		// 首页社区活动
		async getActivityData() {
			try {
				const res = await getHomeActivity()
				this.activity = res.data
			} catch (error) {
				console.log(error)
			}
		},
		// 首页快捷入口
		async getTable() {
			try {
				const res = await getTableData()
				this.table = res.data
			} catch (error) {
				console.log(error)
			}
		},
		// 文章详情
		async getDetail(data) {
			try {
				const res = await getActivityDetail(data)
				this.activityDetail=res.data
			} catch (error) {
				console.log(error)
			}
		}
	}
})